package com.zmn.uac.client;

import com.alibaba.fastjson.JSON;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.uac.UacException;
import com.zmn.uuc.common.constant.DubboConsts;
import com.zmn.uuc.common.dio.integrate.UserRegisterMobileAndLoginByUserIdDIO;
import com.zmn.uuc.dubbo.interfaces.integrate.UserLoginIntegrateRemoteService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * @title: 个人用户注册Dubbo接口
 * @author:Rananquan
 * @Date:2022/6/9 11:55
 */
@Slf4j
@Component
public class UserLoginIntegrateClient {

    @DubboReference(version = DubboConsts.INTERFACE_VERSION, check = false)
    UserLoginIntegrateRemoteService userLoginIntegrateRemoteService;

    /**
     * 通过手机号和验证码注册并登录
     * @param dio 注册信息
     * @return 三方账号token
     */
    public ResponseDTO<String> registerAndLoginThirdByMobile(UserRegisterMobileAndLoginByUserIdDIO dio){
        log.info("通过手机号和验证码注册并登录入参：{}", JSON.toJSONString(dio));
        ResponseDTO<String> tokenResponse = userLoginIntegrateRemoteService.registerAndLoginThirdByMobile(dio);
        if(!tokenResponse.isSuccess()){
            log.error("通过手机号和验证码注册并登录请求失败，失败原因：{}",tokenResponse.getMessage());
            return ResponseDTO.fail(tokenResponse.getMessage());
        }

        String token = tokenResponse.getData();
        log.info("通过手机号和验证码注册并登录返回response：{}",token);

        return tokenResponse;
    }
}
